package com.jsz.peini.redis.util;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jsz.peini.bean.redDate.RedDate;
import com.jsz.peini.redis.base.RedisConstants;
import com.jsz.peini.redis.base.RedisUtil;
import com.jsz.peini.redis.base.SerializeUtil;

public class RedDateRedisUtil {
	private static final Logger logger = LoggerFactory.getLogger(RedDateRedisUtil.class);
	public static void addRedDateRedis(RedDate redDate){
		RedisUtil.lpush(RedisConstants.redDateList.getBytes(), SerializeUtil.serialize(redDate));

		
		
	}
	/**
	 * 获取领取红包的缓存
	 * @return
	 */
	public static List<RedDate> getRedDateList(){
		try {
			RedDate redDate = null;
			List<byte[]> list = RedisUtil.brpop(RedisConstants.redDateList.getBytes());;
			List<RedDate> redDatelist=new ArrayList<RedDate>();
			if(list.size() == 0){
				return null;
			}
			else
			{
				for(int i=1;i<list.size();i++)
				{
					if(list.get(i) != null){
						redDate = (RedDate)SerializeUtil.unserialize(list.get(i));
						redDatelist.add(redDate);
					}
				}
				
				
			}
			return redDatelist;
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return null;
	}
	

}
